package com.jyw.web.controller.system;

import cn.hutool.core.lang.tree.Tree;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.enums.BusinessType;
import com.jyw.system.domain.SysOrderFaultConfig;
import com.jyw.system.domain.dto.SysOrderFaultConfigEditDto;
import com.jyw.system.domain.vo.SysOrderFaultConfigVo;
import com.jyw.system.domain.vo.SysTimelinessRateConfigVo;
import com.jyw.system.service.ISysOrderFaultConfigService;
import com.jyw.system.service.ISysTimelinessConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Created by ZhangCheng on 2023/08/16 (系统时效性配置)
 */
@Api(tags = "系统时效性配置")
@RestController
@RequestMapping("/system/timelinessConfig")
public class SysTimelinessConfigController {

    @Resource
    private ISysTimelinessConfigService sysTimelinessConfigService;

    @Resource
    private ISysOrderFaultConfigService sysOrderFaultConfigService;

    /**
     * 获取系统时效性评级规则配置
     *
     * @return
     */
    @GetMapping("/getRateConfig")
    @ApiOperation("获取系统时效性评级规则配置")
    public CommonResult<SysTimelinessRateConfigVo> getRateConfig() {
        return CommonResult.success(sysTimelinessConfigService.getDefaultRateConfig());
    }

    /**
     * 修改系统时效性评级规则配置
     *
     * @param sysTimelinessRateConfigVo
     * @return
     */
    @Log(title = "修改系统时效性评级规则配置", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRateConfig")
    @ApiOperation("修改系统时效性评级规则配置")
    public CommonResult updateRateConfig(@RequestBody SysTimelinessRateConfigVo sysTimelinessRateConfigVo) {
        sysTimelinessConfigService.updateRateConfig(sysTimelinessRateConfigVo);
        return CommonResult.success();
    }

    /**
     * 查询系统工单故障分类耗时配置树形结构
     *
     * @return
     */
    @GetMapping("/queryTreeList")
    @ApiOperation("查询系统工单故障分类耗时配置树形结构")
    public CommonResult<List<Tree<Long>>> queryTreeList() {
        return CommonResult.success(sysOrderFaultConfigService.queryTreeList());
    }

    /**
     * 查询所有系统工单故障分类耗时配置
     *
     * @return
     */
    @GetMapping("/queryAllList")
    @ApiOperation("查询所有系统工单故障分类耗时配置")
    public CommonResult<List<SysOrderFaultConfigVo>> queryAllList() {
        return CommonResult.success(sysOrderFaultConfigService.queryAllList());
    }

    /**
     * 修改系统工单故障分类耗时配置
     *
     * @param editDto
     * @return
     */
    @Log(title = "修改系统工单故障分类耗时配置", businessType = BusinessType.UPDATE)
    @PutMapping("/updateTime")
    @ApiOperation("修改系统工单故障分类耗时配置")
    public CommonResult updateTime(@RequestBody @Valid SysOrderFaultConfigEditDto editDto) {
        System.out.println("edit=====");
        System.out.println(editDto);
        sysOrderFaultConfigService.updateTime(editDto);
        return CommonResult.success();
    }
}
